<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="/OL_SDK/include-openlayers-local.js"></script>
</head>

<body>
    <div id="map">

    </div>
    <script>
        var gaode = new ol.layer.Tile({
            title: "高德地图",
            source: new ol.source.XYZ({
                url: 'http://wprd0{1-4}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&style=7&x={x}&y={y}&z={z}',
                wrapX: false
            })
        });
        const map = new ol.Map({
            target: "map",
            /* 设置地图图层 */
            // layers: [gaode],
            layers: [],
            /* view设置地图 以坐标,中心点,放大级别 */
            view: new ol.View({
                center: [114.30, 30.50],
                zoom: 4,
                //经纬度坐标系
                projection: "EPSG:4326"
            })
        })
        map.addLayer(gaode)  // 直接在属性里添加，或者属性里不加，之后再用addLayer添加。
        console.log(map)// e{}
        map.on("click", () => {
            map.removeLayer(gaode)
        })

        // ol.proj.transform([114,30],'EPSG:4326','EPSG:3857')
        // 可以将经纬度，转化为墨卡托。
        const mkt = ol.proj.transform([114, 30], 'EPSG:4326', 'EPSG:3857')
        console.log(mkt)// [12690421.950433187, 3503549.843504374]
    </script>
</body>

</html>